#!/bin/sh
cd "${0%/*}" || exit 1    # Run from this directory

# Source tutorial run functions
. "$WM_PROJECT_DIR/bin/tools/RunFunctions"

usage () {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat <<USAGE
Usage: ${0##*/} [OPTIONS]

Options:
  -i | -interface      no refinement in vertical direction of the mesh
  -l | -local          mesh with local refinement
  -h | -help           help

Ship hull simulation to demonstrate two different meshing strategies that can be
used with PLIC type schemes.

USAGE
    exit 1
}

meshType=0

# OPTIONS
while [ "$#" -gt 0 ]
do
    case "$1" in
    -i | -interface)
        meshType=1
        break
        ;;
    -l | -local)
        meshType=2
        break
        ;;
    -h | -help)
        usage
        ;;
    -test)
        shift
        ;;
    -*)
        usage "Invalid option '$1'"
        ;;
    *)
        usage "Invalid option '$1'"
        break
        ;;
    esac
done

if [ $meshType -eq 0 ] || [ $meshType -eq 1 ]; then
{
    ./Allmesh.1
}
elif [$meshType -eq 2 ]; then
{
    ./Allmesh.2
}
fi

runApplication -a decomposePar -fields -copyZero

runParallel setFields

runParallel foamRun

runApplication reconstructPar

#------------------------------------------------------------------------------
